var Sequelize = require('sequelize');
var models = require('../../models');
var opLogDao = module.exports;

opLogDao.createLog = async function (log){
    return models.admin.AdminOpLog.create(log);
};

opLogDao.getLogByKeywords = async function (keywords, offset, limit) {
    var where = {};
    if (keywords && keywords.length != 0) {
        where.operations = {
            [Sequelize.Op.like]: '%'+keywords+'%'
        };
    }
    return models.admin.AdminOpLog.findAndCountAll({
        where: where,
        order: [['operate_time', 'DESC']],
        offset: Number(offset),
        limit: Number(limit),
    });
};

opLogDao.deleteLogs = async function (pks) {
    return models.admin.AdminOpLog.destroy({
        where: {
            id: pks
        }
    });
};

